import config from '../../etc/config'
var app = getApp();
Page({
  data: {
    id: '',
    goodsList: [],
    yunPrice: "0.00",
    detailsList: {},
    secondRepairRemakes: [],
    secondRepairTimes: [],
    // queryComment: {},
    array: [],
  },

  onLoad: function(e) {
    wx.hideShareMenu()
    if (e.orderId) {
      this.getorderDetail(e.orderId)
    }
  },
  onShow: function() {

  },

  // 获取评价
  getqueryComment(orderId) {
    let params = {
      orderId: orderId
    }
    let token = wx.getStorageSync('token')
    config._post('/order/queryComment', token, params).then(res => {
      console.log(res)
      if (res.data) {
        this.setData({
          queryComment: res.data.comment,
          array: res.data.comment.images
        })
      }
    })
  },

  // 获取订单详情
  getorderDetail(orderId) {
    let params = {
      orderId: orderId
    }
    let secondRepairRemakes = [];
    let secondRepairTimes = [];
    let token = wx.getStorageSync('token')
    config._post('/order/detail', token, params).then(res => {
      console.log(res)
      if (res.data) {
        var secondSevers = []
        if (res.data.order.secondRepairRemakes){
          for (let i = 0; i < res.data.order.secondRepairRemakes.length; i++) {
            let option = {
              remark: res.data.order.secondRepairRemakes[i],
              time: res.data.order.secondRepairTimes[i]
            }
            secondSevers.push(option)
          }
        }
        this.setData({
          detailsList: res.data.order,
          deliverymanName: res.data.deliverymanName,
          deliverymanPhone: res.data.deliverymanPhone,
          shopName: res.data.shopName,
          secondSevers: secondSevers
        })
      }
      if (this.data.detailsList.orderStatus == 2 && this.data.detailsList.payStatus === 2 && this.data.detailsList.serviceStatus == 4 && this.data.detailsList.commentStatus == 2) {
        this.getqueryComment(orderId)
      }
    })
  },

  // 拨打电话
  call(e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.mobile //仅为示例，并非真实的电话号码
    })
  }
})